﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Genrsis.WorkitemTracking.Commands;
using Genrsis.WorkitemTracking.Domain;
using Raven.Client;

namespace Genrsis.WorkitemTracking.Handlers.Workflows
{
    public class EditWorkflowNameCommandHandler : ICommandHandler<EditWorkflowNameCommand>
    {
        private readonly IDocumentStore _documentStore;

        public EditWorkflowNameCommandHandler(IDocumentStore documentStore)
        {
            _documentStore = documentStore;
        }

        public void Handle(EditWorkflowNameCommand command)
        {
            using (var session = _documentStore.OpenSession())
            {
                var workflow = session.Load<Workflow>(command.WorkflowId);
                workflow.Rename(command.NewName);

                session.SaveChanges();
            }
        }
    }
}
